package top.lyjwn.ajui.test;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import top.lyjwn.ajui.R;
import top.lyjwn.ajui.data.Message;

/**
 * 聊天内容
 *
 * @author luoyujie
 */
public class ChatContent extends LinearLayout {

    private LinearLayout opposite_message_container;
    private LinearLayout mine_message_container;
    private TextView opposite_message_text;
    private TextView mine_message_text;

    private Message message;


    public ChatContent(Context context) {
        this(context,null);
    }

    public ChatContent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.item_chat_content, this);
        opposite_message_container=  view.findViewById(R.id.opposite_message_container);
        mine_message_container = view.findViewById(R.id.mine_message_container);
        opposite_message_text = view.findViewById(R.id.opposite_message_text);
        mine_message_text = view.findViewById(R.id.mine_message_text);
    }

    public Message getMessage() {
        return message;
    }

    public void setMessage(Message message) {
        this.message = message;
        if (message.getSender().getId().equals(UserUtil.getUser().getId())){
            opposite_message_container.setVisibility(GONE);
            mine_message_text.setText(message.getContent().getText());
        }else{
            mine_message_container.setVisibility(GONE);
            opposite_message_text.setText(message.getContent().getText());
        }
    }
}
